package org.carabiner.infinitest.swingui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * @author <a href="mailto:benrady@gmail.com"Ben Rady</a>
 */
class FailureCellRenderer extends DefaultTreeCellRenderer
{
  public FailureCellRenderer()
  {
  }

  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

    if (value instanceof InfinitestTreeNode)
    {
      InfinitestTreeNode node = (InfinitestTreeNode) value;
      Icon icon = node.getIcon();
      if (icon != null)
        label.setIcon(icon);
      Color customTextColor = node.getColor();
      if (customTextColor != null)
        label.setForeground(customTextColor);
    }
    return label;
  }

}
